using System.Collections.Generic;
using System.Linq;

namespace Fuse8.ContentManagementFramework.Domain.Special
{
    public class CmsSiteEntities
    {
        public CmsSite Site { get; set; }
        public CmsSiteGroup SiteGroup { get; set; }
        public List<CmsContentType> ContentTypes { get; set; }
        public List<CmsContent> Contents { get; set; }
        public List<CmsTemplate> Templates { get; set; }
        public List<CmsTemplateRegion> TemplateRegions { get; set; }
        public List<CmsMedia> Media { get; set; }
        public List<CmsMediaContent> MediaContents { get; set; }
        public List<CmsMediaFile> MediaFiles { get; set; }
        public List<CmsMediaContentFileLink> MediaContentFileLinks { get; set; }
        public List<CmsModule> Modules { get; set; }
        public List<CmsPage> Pages { get; set; }
        public List<CmsPageControl> PageControls { get; set; }
        public List<CmsMimeType> MimeTypes { get; set; }

        public List<CmsEntityMetaField> MetaFields { get; set; }
        public List<CmsEntityMetaFieldLink> MetaFieldLinks { get; set; }
        public List<CmsEntityMeta> Metas { get; set; }

        public void AppendEntityMetaInformation(CmsEntityMetaInformation entityMetaInformation)
        {
            if (entityMetaInformation.MetaFields != null)
            {
                foreach (var metaField in entityMetaInformation.MetaFields
                    .Where(metaField => !MetaFields.Contains(metaField)))
                {
                    MetaFields.Add(metaField);
                }
            }

            if (entityMetaInformation.MetaFieldLinks != null)
            {
                foreach (var metaFieldLink in entityMetaInformation.MetaFieldLinks
                    .Where(metaFieldLink => !MetaFieldLinks.Contains(metaFieldLink)))
                {
                    MetaFieldLinks.Add(metaFieldLink);
                }
            }


            if (entityMetaInformation.Metas != null)
            {
                foreach (var entityMeta in entityMetaInformation.Metas
                    .Where(entityMeta => !Metas.Contains(entityMeta)))
                {
                    Metas.Add(entityMeta);
                } 
            }
        }

        public void AppendEntityMetaInformation(IEnumerable<CmsEntityMetaInformation> entityMetaInformations)
        {
            foreach (var cmsEntityMetaInformation in entityMetaInformations)
            {
                AppendEntityMetaInformation(cmsEntityMetaInformation);
            }
        }

        public CmsSiteEntities ()
        {
            MetaFields = new List<CmsEntityMetaField>();
            MetaFieldLinks = new List<CmsEntityMetaFieldLink>();
            Metas = new List<CmsEntityMeta>();
        }
    }
}